<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_cartoCSSNaturalStyle"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
    <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
<div id="map" style="width: 100%;height:100%"></div>
<script type="text" id="cartoCssStr">
        /*此处定义不同的颜色变量，在后面可以重复用这些颜色值*/

        @waterColor:rgb(109,183,255);
        @roadColora:rgb(100,100,100);
        @roadColorb:rgb(250,250,250);
        @railwayColora:rgb(186,186,186);
        @railwayColorb:rgb(250,250,250);
        @vegetationColor:rgb(193,220,185);
        @continentColor:rgb(183,202,147);
        @provinceLineColor:rgb(100,100,100);


         /*中国除外的其他国家的图层*/

        #World_Continent_pl___China{
        polygon-fill:@continentColor;
        line-width:1;
        line-color:@continentColor;
        }
        #China_Province_pl___China{
        polygon-fill:@continentColor;
        line-color:rgba(0,0,0,0);
        }

        #Arterial_Road_ln___China::one{
        line-color:@roadColora;
        line-width:2;}
        #Arterial_Road_ln___China::two{
        line-color:@roadColorb;
        line-width:1;}

        #Arterial_Road_ln___China___1::one{
        line-color:@roadColora;
        line-width:2;}
        #Arterial_Road_ln___China___1::two{
        line-color:@roadColorb;
        line-width:1;}

        #Arterial_Road_ln___China___1___1::one{
        line-color:@roadColora;
        line-width:2;}
        #Arterial_Road_ln___China___1___1::two{
        line-color:@roadColorb;
        line-width:1;}

        #Main_Road_L___China::one{
        line-color:@roadColora;
        line-width:2;}
        #Main_Road_L___China::two{
        line-color:@roadColorb;
        line-width:1;}

        #Main_Road_L___China___1::one{
        line-color:@roadColora;
        line-width:2;}
        #Main_Road_L___China___1::two{
        line-color:@roadColorb;
        line-width:1;}

        #Main_Road_L___China___1___1::a{
        line-color:@roadColora;
        line-width:2;}
        #Main_Road_L___China___1___1::b{
        line-color:@roadColorb;
        line-width:1;}

        #Hydside_Area_pl___Hydside{
        polygon-fill:@waterColor;
        line-color:@waterColor;
        }

        #China_Provinces_L___China400{
        line-dasharray:10,10;
        line-color:@provinceLineColor;
        line-width:1;
        }
</script>

<script type="text/javascript">
    var url = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-china/rest/maps/China";
    new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
        var map = new ol.Map({
            target: 'map',
            // ol v7版本用法为ol.control.defaults.defaults； v6版本以下用法为ol.control.defaults
            controls: ol.control.defaults.defaults({attributionOptions: {collapsed: false}})
                .extend([new ol.supermap.control.Logo({ link: "https://iclient.supermap.io" })]),
            view: new ol.View({
                center: [12957388, 4853991],
                zoom: 11,
                multiWorld: true
            })
        });
        var stylesOptions = {
            url: url,
            view: map.getView(),
            donotNeedServerCartoCss: true,
            cartoCss: document.getElementById("cartoCssStr").text
        }
        var vectorTileStyles = new ol.supermap.VectorTileStyles(stylesOptions);
        var vectorTileOptions = ol.source.VectorTileSuperMapRest.optionsFromMapJSON(url, serviceResult.result);
        vectorTileOptions.returnAttributes = false;
        var vectorLayer = new ol.layer.VectorTile({
            source: new ol.source.VectorTileSuperMapRest(vectorTileOptions),
            style: vectorTileStyles.getFeatureStyle
        });
        map.addLayer(vectorLayer);
        map.on('click', function (e) {
            map.forEachFeatureAtPixel(e.pixel, function (feature) {
                vectorTileStyles.dispatchEvent({type: 'featureSelected',
                    selectedId: feature.getProperties().id,
                    layerName: feature.getProperties().layerName
                });
                return true;
            }, {hitTolerance: 5});
            vectorLayer.changed();
        })

    });
</script>
</body>
</html>